using System;
using System.Collections.Generic;
using System.Text;
using HappySprite;
using HappySprite.Simulation;

namespace HappyInvaders
{
    class InvaderEntity : Entity
    {
        int index;
        int row;

        public InvaderEntity()
        {
            Item.CollisionShape = Box.CreateFromSize(Constants.InvaderWidth, Constants.InvaderHeight);
            Item.CollisionGroup = Constants.InvaderGroup;
            Item.CollisionMask = Constants.BulletGroup | Constants.ShelterGroup | Constants.PlayerGroup;
            Item.Collision += CollisionHandler;
        }

        public int Index
        {
            get { return index; }
            set { index = value; }
        }

        public int Row
        {
            get { return row; }
            set { row = value; }
        }

        protected override bool ShouldUpdate
        {
            get { return !PositionCurrent; }
        }

        internal override void OnRemove()
        {
            Owner.InvaderRemoved(Index);
        }

        void CollisionHandler(CollisionEventArgs e)
        {
            if (e.Other.Tag is BulletEntity)
            {
                Remove();
                Owner.CreateZap(Position);

                // Apply score
                int type = (5 - row) / 2;

                switch (type)
                {
                    case 0: Owner.Score += 30; break;
                    case 1: Owner.Score += 20; break;
                    default: Owner.Score += 10; break;
                }
            }
        }
    }
}
